<template>
	<view class="fillInLogistics">
		<view class="main">
			<view class="refund">
				<view class="goods">
					<view class="left">
						<image :src="data.httpUrl+'/app/file/viewFile?fileId='+data.info.mainPictureId"
							mode="aspectFill"></image>
					</view>
					<view class="right">
						<text class="ellipsis_2">{{data.info.spuName}}</text>
						<view>
							{{data.info.specName}}，{{data.info.specValue}}
							<text>x {{data.info.count}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="info">
				<view class="">
					收货信息
					<text>{{data.info.sellerAddress.rcvName}} {{data.info.sellerAddress.rcvPhone}}
						{{data.info.sellerAddress.address}}</text>
				</view>
				<view class="">
					填写单号
					<input v-model="data.logisticsNo" type="text" placeholder="填写单号" />
					<image @tap="scanCode" style="width:40rpx;margin-left:20rpx;" src="/static/img/index/78.png" mode="widthFix">
					</image>
				</view>
			</view>
		</view>
		<view class="bot">
			<text @tap="submit">提交</text>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { reactive } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import { getRefundDetail, buyerSend } from '@/utils/api/goods'
	const data = reactive<any>({
		info: { sellerAddress: {} },
		httpUrl: getApp().globalData.baseUrl,
		logisticsNo: ''
	})
	onLoad(({ refundNo }) => {
		data.refundNo = refundNo;
		getRefundDetail({ data: { refundNo } }).then((res) => {
			data.info = res.data;
			data.logisticsNo = res.data.buyerLogisticsNo
		})

	})
	const scanCode=()=>{
		uni.scanCode({
			success: function (res) {
				data.logisticsNo = res.result;
				
			}
		});
	}
	const submit = () => {
		if (!data.logisticsNo) {
			uni.showToast({
				title: '请填写快递单号!',
				icon: 'none'
			})
			return;

		}
		uni.showLoading({
			title: '加载中...',
			mask: true
		})
		buyerSend({ data: { refundNo: data.refundNo, logisticsNo: data.logisticsNo } }).then((res) => {
			if (res.code == 200) {
				uni.showToast({
					title: '提交成功!',
					icon: "none"
				})
				setTimeout(() => {
					uni.navigateBack()
				}, 1000)
			}
		})
	}
</script>

<style lang="scss">
	.fillInLogistics {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #F5F5F5;

		.main {
			flex: 1;
			padding: 24rpx;
		}

		.info {
			padding: 24rpx;
			border-radius: 24rpx;
			background: #fff;
			margin-top: 20rpx;

			>view:nth-of-type(2) {
				margin-top: 32rpx;
				align-items: center;
			}

			>view {
				display: flex;

				text {
					flex: 1;
					margin-left: 16rpx;
				}

				input {
					height: 64rpx;
					flex: 1;
					margin-left: 16rpx;
					background: #F5F5F5;
					border-radius: 20rpx;
					padding-left: 20rpx;
				}
			}
		}

		>.bot {
			display: flex;
			background: #fff;
			padding: 20rpx 56rpx;

			text {
				width: 100%;
				line-height: 80rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
				border-radius: 80rpx;
				background: #6B64D3;
			}
		}
	}

	.refund {
		padding: 24rpx;
		border-radius: 24rpx;
		background: #fff;
		font-size: 32rpx;

		.goods {
			display: flex;

			.left {
				width: 150rpx;
				height: 150rpx;
				background: #ccc;
				margin-right: 24rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.right {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				view {
					color: #8C8C8C;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}
		}
	}
</style>